package com.lovo.csc.controller;

import com.alibaba.fastjson.JSON;
import com.lovo.commom.util.MD5Encryptor;
import com.lovo.commom.vo.ResultVO;
import com.lovo.csc.bean.AdminBean;
import com.lovo.csc.service.IAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.security.NoSuchAlgorithmException;


@RestController
@RequestMapping("admin")
public class AdminController {
    @Autowired
    private IAdminService service;

    /**
     *  后端管理员登录
     */
    @GetMapping("login")
    public ResultVO login(String userName, String pwd) throws NoSuchAlgorithmException {
        AdminBean adminBean = service.login(userName, MD5Encryptor.encrypt(pwd));
        ResultVO resultVO = new ResultVO();
        if (adminBean != null){
            //把对象转换成json
            String json = JSON.toJSONString(adminBean);
//            //生成Token
//            String token = CreateToken.createToken(json);
            resultVO.setTag(0);
            resultVO.setJson(json);
        }else {
            resultVO.setTag(1);
            resultVO.setJson("");
        }

        return resultVO;
    }



}
